<?php
	require_once("AJS.php");
	require_once("IMG.class.php");

	class CustomCheckBox{
		//TODO : améliorer : image inactive désuette si image inactive= image active + '_bw'
		var $imageActive;
		var $imageInactive;
		var $name;
		var $active;
		
		public function CustomCheckBox($imageActive,$imageInactive,$name,$active=true){
			$this->imageActive = $imageActive;
			$this->imageInactive = $imageInactive;
			$this->name = $name;
			$this->active = $active;
		}
		
		public function __toString(){
			$value = ($this->active)? 1:0;
			$image = ($this->active)? $this->imageActive:$this->imageInactive;
			$click = ($this->active)? 'setFalse(this)':'setTrue(this)';
			$hidden = '<input type="hidden" value="'.$value.'" name="'.$this->name.'"/>';
			$img = new AJS(new IMG($image,$this->name),"Javascript:".$click.";",$this->name);
			return '<span id="'.$this->name.'">'.$hidden.$img.'</span>';
		}
	}
?>
        
<script type="text/javascript">
	function setTrue(bloc){
		blocCCB = bloc.parentNode;
		blocCCB.getElementsByTagName('img')[0].src = <?php echo $GLOBALS['PHPFoxEngine']->data->baseURL; ?>+'css/imgstyle/'+blocCCB.getElementsByTagName('img')[0].alt+'.png';
		blocCCB.getElementsByTagName('input')[0].value = 1;
		blocCCB.getElementsByTagName('a')[0].setAttribute('onclick','Javascript:setFalse(this);');
	}
	
	function setFalse(bloc){
		blocCCB = bloc.parentNode;
		blocCCB.getElementsByTagName('img')[0].src = <?php echo $GLOBALS['PHPFoxEngine']->data->baseURL; ?>+'css/imgstyle/'+blocCCB.getElementsByTagName('img')[0].alt+'_bw.png';
		blocCCB.getElementsByTagName('input')[0].value = 0;
		blocCCB.getElementsByTagName('a')[0].setAttribute('onclick','Javascript:setTrue(this);');
	}
</script>
